<!-- JAVASCRIPT -->

function getObj(id) {
	return document.getElementById(id);
}

function rand ( n )
{
  return ( Math.floor ( Math.random ( ) * n + 1 ) );
}

function findPlaces(islist, ismap, clearoverlay)
{
	var baseurl = "http://pipes.yahoo.com/pipes/pipe.run?_id=urhkrL_N3BGBwlgZJxOy0Q&_render=rss";
	var addr = "New York";
	var biz="Resturants";
	var rnd="483";
	var star="";

	// get value from textbox
	var idvisitObj = getObj('id_visit');
	if(idvisitObj != null) {
		biz = idvisitObj.value;
	}

	var idstarObj = getObj('id_star');
	if(idstarObj != null) {
		star = idstarObj.value;
	}

	var idaddrObj = getObj('id_addr');
	if(idaddrObj != null) {
		addr = idaddrObj.value;
	}

	// invoke URL and get datafeed
	var dataFeedUrl = baseurl+"&addr="+escape(addr)+"&biz="+biz+"&star="+star+"&rnd=483";
	//alert('findPl'+dataFeedUrl);
	//alert('findpl');
	//alert(islist);
	if(islist == 1) {
		refreshList(dataFeedUrl, 'id_places');
	}
	// temp comment...
	//alert(ismap);
	if(ismap == 1) {
		refreshMap(dataFeedUrl, 'id_map_travelmeetup', clearoverlay);
	}
	// Set data feed for the list dynamically
}

var toggle=1;

function refreshContacts()
{
	// random numbers to fetch non-cached data (workaround for google caching)
	var rnd10 = rand(1000);
	var rnd11 = rand(1200);
      var baseurl10 = "http://pipes.yahoo.com/pipes/pipe.run?_id=0JSyeaCV3BGlubsUJphxuA&_render=rss"+"&param1="+rnd10; // 2 contacts
      var baseurl11 = "http://pipes.yahoo.com/pipes/pipe.run?_id=iJ5fXmqW3BG_05hwEpPZnA&_render=rss"+"&param1="+rnd11; // 3 contacts

	// invoke URL and get datafeed
	var dataFeedUrl = baseurl10;
      if(toggle==1) {
		toggle=0;
		dataFeedUrl = baseurl11;
	} else {
		toggle=1;
		dataFeedUrl = baseurl10;
	}

	//alert('findGroup'+dataFeedUrl);
	//alert('findpl');
	refreshList(dataFeedUrl, 'id_contacts');
}

function refreshList(dataFeedUrl, id) 
{
	var listModulePlaces = google.mashups.getObjectById(id);
	listModulePlaces.setData(dataFeedUrl);
}

function refreshMap(dataFeedUrl, id, clearoverlay)
{
	//alert('refresh map'+dataFeedUrl + ' ' + id);
	var mapModulePlaces = google.mashups.getObjectById(id);
	//alert("refreshMap");
	if(clearoverlay == 1) {
		mapModulePlaces.getMap().clearOverlays();
	}
      mapModulePlaces.getMap().addOverlay(new GGeoXml(dataFeedUrl));
	mapModulePlaces.showAllMarkers();

}

/***************** Timer Code *********************/

var secs
var timerID = null
var timerRunning = false
var delay = 1000

var recurtimer = 1; // override to keep receiving updates

function InitializeTimer()
{
    //alert("InitializeTimer1");
    // Set the length of the timer, in seconds
    secs = 10
    StopTheClock()
    StartTheTimer()
}

function StopTheClock()
{
    if(timerRunning)
        clearTimeout(timerID)
    timerRunning = false
}

function StartTheTimer()
{
    if (secs==0)
    {
        StopTheClock()
        // supposed to happen after the allotted time.
        //alert("After timer activated.")
	  refreshContacts();
        if(recurtimer==1) {
		  InitializeTimer();
	  }
    }
    else
    {
        self.status = secs
        secs = secs - 1
        timerRunning = true
        timerID = self.setTimeout("StartTheTimer()", delay)
    }
}

function setRecurTimerOn() {
   recurtimer=1;
}

function setRecurTimerOff() {
   recurtimer=0;
}

